package com.seventh.parkingrent.controller;


import com.seventh.parkingrent.commens.Result;
import com.seventh.parkingrent.controller.form.RentMessageFormForFront;
import com.seventh.parkingrent.service.IRentMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/**
 * <p>
 * 订单详情记录表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
@RestController
@Slf4j
@CrossOrigin("*")
public class RentMessageController {
    @Resource
    private IRentMessageService rentMessageService;

    @GetMapping("/getRentMessageByCondition")
    public Result getRentMessageByCondition(String status,String lessor,String tenantry,String rentStartTimeStart,String rentStartTimeEnd,String rentEndTimeStart,String rentEndTimeEnd,String propertyName) throws ParseException {
        log.info("获得前端查询订单数据status={},lessor={},tenantry={}," +
                "rentStartTimeStart={},rentStartTimeEnd={}," +
                "rentEndTimeStart={},rentEndTimeEnd={}," +
                "propertyName={}",
                status,lessor,tenantry,
                rentStartTimeStart,rentStartTimeEnd,rentEndTimeStart,
                rentEndTimeEnd,propertyName);
        if(""==status){
            status=null;
        }
        if(""==lessor){
            lessor=null;
        }
        if(""==tenantry){
            tenantry=null;
        }
        if(""==propertyName){
            propertyName=null;
        }

        List<RentMessageFormForFront> form = rentMessageService.getRentMessageByCondition
                (status,lessor,tenantry,
                rentStartTimeStart,rentStartTimeEnd,rentEndTimeStart,
                rentEndTimeEnd,propertyName);


        return Result.success(form);
    }


    @GetMapping("/getLessor")
    public Result getLessor(){
        log.info("前端提请获取出租方名字");

        List<String> lessor = rentMessageService.getLessor();
        return Result.success(lessor);
    }

    @GetMapping("/getTenantry")
    public Result getTenantry(){
        log.info("前端提请获取抢租客名字");
        List<String> tenantry = rentMessageService.getTenantry();
        return Result.success(tenantry);
    }
}

